package com.mipo.company.flytek.jxt.authourity.beilun;

import java.net.URLDecoder;

import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class Product {
	public static void main(String[] args) throws Exception {
		//authNew();
		queryStatus();
		
	}
	
	// 新授权
	public static void authNew() throws Exception {
		String url = "http://nbbl.book.changyan.cn/index.php?c=home&a=doRegisterForCustomized&provinceCode=330000&cityCode=330200&districtCode=330206&cardId=48205415-2469-9AFA-5D2E-316411EA535F&loginName=lijie_test&schoolId=238259235783&product=rrt_nbbl";
		excuteGetRequest(url);
	}
	
	// 查询状态
	public static void queryStatus() throws Exception {
		String url = "http://nbbl.book.changyan.cn/index.php?c=home&a=getUserCardState&loginName=duansq&appName=rrt_nbbl";
		excuteGetRequest(url);
	}
	
	public static void excuteGetRequest(String url) throws Exception {
		System.out.println("请求url："+url);
		CloseableHttpClient httpClient = HttpClients.createDefault();
		HttpGet httpGet = new HttpGet(url);
		CloseableHttpResponse response = httpClient.execute(httpGet); // 4.3版本不设置超时的话，一旦服务器没有响应，等待时间N久(>24小时)。
		HttpEntity entity = response.getEntity(); // 返回报文实体
		StatusLine status = response.getStatusLine();
		System.out.println("返回的状态码为：" + status); // 具体返回码(200)为status.getStatusCode();
		String ret = EntityUtils.toString(entity); // 将返回报文实体转换为字符串
		System.out.println("返回的报文为：" + URLDecoder.decode(ret,"UTF-8"));
		EntityUtils.consume(entity); // 释放是否可以去掉？
		response.close(); // 关闭资源,可以写在finally里
		httpGet.releaseConnection(); // 释放资源
		httpClient.close(); // 关闭资源
	}
}
